//
//  CJBannerGMAdapter.m
//  CJModileGMAdapter
//
//  Created by shanghailingye on 2024/4/24.
//

#import "CJBannerGMAdapter.h"


@interface CJBannerGMAdapter()<CJBannerAdDelegate>

@property (nonatomic, strong) CJBannerAd *bannerAd;
@property (nonatomic, strong) UIView *bannerView;

@end
@implementation CJBannerGMAdapter


- (BUMMediatedAdStatus)mediatedAdStatus {
    BUMMediatedAdStatus status = BUMMediatedAdStatusNormal;
    return BUMMediatedAdStatusNormal;
}

- (void)loadBannerAdWithSlotID:(nonnull NSString *)slotID andSize:(CGSize)adSize parameter:(nullable NSDictionary *)parameter {
    CGRect rect = CGRectMake(0, 0, adSize.width, adSize.height);
    self.bannerAd = [[CJBannerAd alloc] initWithResourceId:slotID rootViewController:self.bridge.viewControllerForPresentingModalView rect:rect];
    self.bannerAd.delegate = self;
    [self.bannerAd loadAdData];
}

- (void)_mixNativeloadNativeAdWithSlotID:(nonnull NSString *)slotID andSize:(CGSize)size imageSize:(CGSize)imageSize parameter:(nonnull NSDictionary *)parameter {

}

- (void)registerContainerView:(nonnull __kindof UIView *)containerView andClickableViews:(nonnull NSArray<__kindof UIView *> *)views forNativeAd:(nonnull id)nativeAd {
}

- (void)didReceiveBidResult:(BUMMediaBidResult *)result {
    // 在此处理Client Bidding的结果回调
}

#pragma mark CJBannerAdDelegate
- (void)bannerAdDidLoad:(nonnull UIView *)bannerView resourceId:(nonnull NSString *)resourceId {
    self.bannerView = bannerView;
    NSInteger cpm = [self.bannerAd getECpm];
    NSDictionary *ext = @{
        BUMMediaAdLoadingExtECPM : cpm ? [NSString stringWithFormat:@"%ld", cpm] : @"0",
    };
    [self.bridge bannerAd:self didLoad:bannerView ext:ext];
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)bannerAdLoadFailed:(nonnull id)bannerAd error:(nonnull NSError *)error {
    [self.bridge bannerAd:self didLoadFailWithError:error ext:@{}];
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)bannerAdOnClicked:(nonnull id)bannerAd {
    [self.bridge bannerAdDidClick:self bannerView:self.bannerView];
}

- (void)bannerAdOnClosed:(nonnull id)bannerAd {
    [self.bridge bannerAd:self bannerView:self.bannerView didClosedWithDislikeWithReason:@[]];
}

- (void)bannerAdOnShow:(nonnull id)bannerAd {
    [self.bridge bannerAdDidBecomeVisible:self bannerView:self.bannerView];
}


@end
